/*
vue-router
1:安装  yarn add vue-router
2:导入  import {createRouter,createWebHashHistory} from 'vue-router'
3:实例化
   const  router=createRouter({
     mode+routes
     history+routes
     history:createWebHashHistory(),
     routes:[
           {
               path,component,redirect....
           }  
     ]
   })
4:暴露出去  export default router
5:在main.ts挂载
   import router from '@/router'
   createApp(APP).use(router).mount("#app")
6:路由出口
   router-view

*/

import { createRouter, createWebHashHistory } from 'vue-router'

const router = createRouter({
  history: createWebHashHistory(),
  scrollBehavior () {
    // ...
    return {
      // vue2:  x,y
      //  vue3:top,left
      top: 0
    }
  },
  routes: [
    {
      path: '/playground',
      component: () => import('@/views/playGround/index.vue')
    },
    {
      path: '/login',
      component: () => import('@/views/login/index.vue')
    },
    {
      path: '/login/callback',
      component: () => import('@/views/login/callback.vue')
    },
    {
      path: '/',
      redirect: '/home',
      component: () => import('@/views/layout/index.vue'),
      children: [
        {
          path: '/home', // 相对写法  ，绝对写法
          component: () => import('@/views/home/index.vue')
        },
        {
          path: '/category/:id', // 相对写法  ，绝对写法
          component: () => import('@/views/category/index.vue')
        },
        {
          path: '/category/sub/:id', // 相对写法  ，绝对写法
          component: () => import('@/views/category/sub.vue')
        },
        {
          path: '/goods/:id', // 相对写法  ，绝对写法
          component: () => import('@/views/goods/index.vue')
        }
      ]
    }
  ]
})
// router.afterEach(() => {
//   window.scrollTo(0, 0)
// })

export default router
